﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;
using System.Threading;
using CloudStorageLight.SampleWeb.Models;
using CloudStorageLight.Core;
using System.Security.Principal;
using System.Diagnostics;
using System.IO;
using CloudStorageLight.Core.Web;

namespace CloudStorageLight.SampleWeb.Controllers
{
    public class HomeController : FilesControllerBase
    {
        protected override BlobServiceBase CreateBlobService()
        {
            return new BlobService();
        }

        public override async Task<ActionResult> Index(string id = "", string snapshot = null, string mode = null)
        {
            if (id == "" && !this.HttpContext.User.Identity.IsAuthenticated) return RedirectToAction("Login", "Account");
            return await base.Index(id, snapshot, mode);
        }

        protected override async Task<object> CreateFilesVM(string id, BlobUser user, BlobServiceBase svc)
        {
            {
                var vm = new FilesVM() { User = user, Current = id };
                vm.Folder = (BlobDirectory)await svc.GetBlobItemAsync(user, id);
                vm.FolderControl = await svc.CanControlAsync(user, id);
                return vm;
            }
        }
    }
}